﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model;

namespace Project
{
    /// <summary>
    /// Interaction logic for ViewDeclarations.xaml
    /// </summary>
    public partial class ViewDeclarations : UserControl
    {
        public string VictimId { get; set; }
        public string AggressorId { get; set; }
        private List<ShowableDeclaration> declarations;
        public long ComplaintId { get; set; }

        public ViewDeclarations(long complaintId)
        {
            InitializeComponent();
            ComplaintId = complaintId;
            declarations = DeclarationDataAccess.GetAllShowableDeclarations(ComplaintId);
            listViewDeclarations.DataContext = declarations;
            lblCaseNumber.Content = ComplaintId;
            UIWindowManager.SetWindowTitle(this,"Brigada De Protección a la Familia - Ver Declaraciones");
            HideMenuOptionsDependingOfUser();
        }

        private void HideMenuOptionsDependingOfUser()
        {
            if (UserControllerAndDataAccess.IsUserLogged())
            {
                if(UserControllerAndDataAccess.IsDirectorLogged)
                    ModDeclarationOp.Visibility = Visibility.Collapsed;
            }
        }

        private void FilterResults()
        {
            if (declarations != null)
            {
                listViewDeclarations.DataContext = DeclarationDataAccess.GetDeclarationsBy(declarations, (cbByWhat.SelectedItem as ComboBoxItem).Content.ToString());
            }
        }

        private void cbByWhat_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listViewDeclarations != null)
            {
                if ((cbByWhat.SelectedItem as ComboBoxItem).Content.ToString() == "Todos")
                {
                    listViewDeclarations.DataContext = declarations;
                }
                else
                {
                    FilterResults();
                }
            }
        }


        private void ModifyDeclaration_OnClick(object sender, RoutedEventArgs e)
        {
            if (listViewDeclarations.SelectedIndex > -1)
            {
                Window w = Window.GetWindow(this.Parent);
                ((MainWindow) w).Content.Children.Clear();
                var questions = (listViewDeclarations.SelectedValue as ShowableDeclaration).QuestionsAndAnswer;
                ((MainWindow)w).Content.Children.Add(new ModifyDeclaration(ComplaintId,questions));
            }
        }

        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            if (listViewDeclarations.SelectedIndex > -1)
            {
                Window w = Window.GetWindow(this.Parent);
                ((MainWindow)w).Content.Children.Clear();
                var questions = (listViewDeclarations.SelectedValue as ShowableDeclaration).QuestionsAndAnswer;
                ((MainWindow)w).Content.Children.Add(new ViewDeclaration(ComplaintId, questions));
            }
        }
    }
}
